package _6_reflect_proxy.custom_proxy;

import _6_reflect_proxy.jdkproxy.ITarget;
import _6_reflect_proxy.jdkproxy.Target;

import java.lang.reflect.Method;

/**
 * @author bpzj 2019/12/11 15:59
 */
public class UseCustomProxy {
    public static void main(String[] args) {
        Target target = new Target();
        Object proxyInstance = CusProxy.newProxyInstance(new CusClassLoader(), target.getClass().getInterfaces(), new CusInvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                System.out.println("向观众问好");
                //执行目标对象方法
                Object returnValue = method.invoke(target, args);
                System.out.println("谢谢大家");
                return returnValue;
            }
        });
        ITarget proxy = (ITarget) proxyInstance;
        proxy.targetMethod();
    }
}
